MutableList

interface MutableList<E> : List<E> , MutableCollection<E>

A generic ordered collection of elements that supports adding and removing elements.

Parameters

E

the type of elements contained in the list. The mutable list is invariant in its element type.

Functions

add
Link copied to clipboard
abstract override fun add(element: E): Boolean

Adds the specified element to the end of this list.

abstract fun add(index: Int, element: E)

Inserts an element into the list at the specified index.

addAll
Link copied to clipboard
abstract override fun addAll(elements: Collection<E>): Boolean

Adds all of the elements of the specified collection to the end of this list.

abstract fun addAll(index: Int, elements: Collection<E>): Boolean

Inserts all of the elements of the specified collection elements into this list at the specified index.

clear
Link copied to clipboard
abstract override fun clear()
contains
Link copied to clipboard
abstract operator override fun contains(element: E): Boolean
containsAll
Link copied to clipboard
abstract override fun containsAll(elements: Collection<E>): Boolean
get
Link copied to clipboard
abstract operator fun get(index: Int): E
indexOf
Link copied to clipboard
abstract fun indexOf(element: E): Int
isEmpty
Link copied to clipboard
abstract override fun isEmpty(): Boolean
iterator
Link copied to clipboard
abstract operator override fun iterator(): Iterator<E>
lastIndexOf
Link copied to clipboard
abstract fun lastIndexOf(element: E): Int
listIterator
Link copied to clipboard
abstract override fun listIterator(): MutableListIterator<E>
abstract override fun listIterator(index: Int): MutableListIterator<E>
remove
Link copied to clipboard
abstract override fun remove(element: E): Boolean
removeAll
Link copied to clipboard
abstract override fun removeAll(elements: Collection<E>): Boolean
removeAt
Link copied to clipboard
abstract fun removeAt(index: Int): E

Removes an element at the specified index from the list.

retainAll
Link copied to clipboard
abstract override fun retainAll(elements: Collection<E>): Boolean
set
Link copied to clipboard
abstract operator fun set(index: Int, element: E): E

Replaces the element at the specified position in this list with the specified element.

subList
Link copied to clipboard
abstract override fun subList(fromIndex: Int, toIndex: Int): MutableList<E>

Properties

size
Link copied to clipboard
abstract override val size: Int

Inheritors

AbstractMutableList
Link copied to clipboard
ArrayList
Link copied to clipboard

Extensions

asReversed
Link copied to clipboard
@JvmName(name = "asReversedMutable")
fun <T> MutableList<T>.asReversed(): MutableList<T>

Returns a reversed mutable view of the original mutable List. All changes made in the original list will be reflected in the reversed one and vice versa.

fill
Link copied to clipboard
expect fun <T> MutableList<T>.fill(value: T)
actual inline fun <T> MutableList<T>.fill(value: T)

Fills the list with the provided value.

actual fun <T> MutableList<T>.fill(value: T)

Fills the list with the provided value.

actual fun <T> MutableList<T>.fill(value: T)

Fills the list with the provided value.

remove
Link copied to clipboard
inline fun <T> MutableList<T>.remove(index: Int): T

Removes the element at the specified index from this list. In Kotlin one should use the MutableList.removeAt function instead.

removeAll
Link copied to clipboard
fun <T> MutableList<T>.removeAll(predicate: (T) -> Boolean): Boolean

Removes all elements from this MutableList that match the given predicate.

removeFirst
Link copied to clipboard
fun <T> MutableList<T>.removeFirst(): T

Removes the first element from this mutable list and returns that removed element, or throws NoSuchElementException if this list is empty.

removeFirstOrNull
Link copied to clipboard
fun <T> MutableList<T>.removeFirstOrNull(): T?

Removes the first element from this mutable list and returns that removed element, or returns null if this list is empty.

removeLast
Link copied to clipboard
fun <T> MutableList<T>.removeLast(): T

Removes the last element from this mutable list and returns that removed element, or throws NoSuchElementException if this list is empty.

removeLastOrNull
Link copied to clipboard
fun <T> MutableList<T>.removeLastOrNull(): T?

Removes the last element from this mutable list and returns that removed element, or returns null if this list is empty.

replaceAll
Link copied to clipboard
fun <T> MutableList<T>.replaceAll(transformation: (T) -> T)

Replaces each element in the list with a result of a transformation specified.

retainAll
Link copied to clipboard
fun <T> MutableList<T>.retainAll(predicate: (T) -> Boolean): Boolean

Retains only elements of this MutableList that match the given predicate.

reverse
Link copied to clipboard
expect fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

actual fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

actual fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

actual fun <T> MutableList<T>.reverse()

Reverses elements in the list in-place.

shuffle
Link copied to clipboard
fun <T> MutableList<T>.shuffle(random: Random)

Randomly shuffles elements in this list in-place using the specified random instance as the source of randomness.

expect fun <T> MutableList<T>.shuffle()
inline fun <T> MutableList<T>.shuffle(random: Random)

Randomly shuffles elements in this mutable list using the specified random instance as the source of randomness.

actual inline fun <T> MutableList<T>.shuffle()

Randomly shuffles elements in this mutable list.

actual fun <T> MutableList<T>.shuffle()

Randomly shuffles elements in this list.

actual fun <T> MutableList<T>.shuffle()

Randomly shuffles elements in this list.

sort
Link copied to clipboard
expect fun <T : Comparable<T>> MutableList<T>.sort()
inline fun <T> MutableList<T>.sort(comparator: Comparator<in T>)
inline fun <T> MutableList<T>.sort(comparison: (T, T) -> Int)

actual fun <T : Comparable<T>> MutableList<T>.sort()

Sorts elements in the list in-place according to their natural sort order.

actual fun <T : Comparable<T>> MutableList<T>.sort()

Sorts elements in the list in-place according to their natural sort order.

actual fun <T : Comparable<T>> MutableList<T>.sort()

Sorts elements in the list in-place according to their natural sort order.

sortBy
Link copied to clipboard
inline fun <T, R : Comparable<R>> MutableList<T>.sortBy(crossinline selector: (T) -> R?)

Sorts elements in the list in-place according to natural sort order of the value returned by specified selector function.

sortByDescending
Link copied to clipboard
inline fun <T, R : Comparable<R>> MutableList<T>.sortByDescending(crossinline selector: (T) -> R?)

Sorts elements in the list in-place descending according to natural sort order of the value returned by specified selector function.

sortDescending
Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.sortDescending()

Sorts elements in the list in-place descending according to their natural sort order.

sortWith
Link copied to clipboard
expect fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)
actual fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)

Sorts elements in the list in-place according to the order specified with comparator.

actual fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)

Sorts elements in the list in-place according to the order specified with comparator.